<%--
  Created by IntelliJ IDEA.
  User: 862982795
  Date: 2021/06/07
  Time: 10:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>水果查询</title>
</head>
<body>
<div align="center">
    <form action="">
        <a href="ListServlet?pageNo=1">首页</a>&nbsp;&nbsp;总页码:${pageNos}&nbsp;&nbsp;当前页码:${pageNo}&nbsp;&nbsp;<a
            href="ListServlet?pageNo=${pageNos}">尾页</a><br>
        &nbsp;&nbsp;
        <c:if test="${pageNo>1}">
            <a href="ListServlet?pageNo=${pageNo-1}">上一页</a>
        </c:if>
        <c:if test="${pageNo<pageNos}">
            <a href="ListServlet?pageNo=${pageNo+1}">下一页</a>
        </c:if>
        <table>
            <caption>水果查询</caption>
            <tr>
                <td>
                    <button type="button" onclick="location.href='add.jsp'">添加</button>
                </td>
            </tr>
            <tr
                    style="font-weight: bold; background-color: yellow; font-size: 15px">
                <td>类别</td>
                <td>品种</td>
                <td>产地</td>
                <td>总重量(公斤)</td>
                <td>单价(元/公斤)</td>
                <td>操作</td>
            </tr>

            <c:forEach var="list" items="${list }" varStatus="status">
                <tr id="${list.fruitId}"
                    <c:if test="${status.index%2==1 }">style="background-color:rgb(219,241,212);"</c:if>>
                    <td>${list.type }</td>
                    <td>${ list.breed}</td>
                    <td>${list.area }</td>
                    <td>${list.weight }</td>
                    <td>${list.price }</td>
                    <td><a href="InfoServlet?fruitId=${list.fruitId }&i=1">修改</a>&nbsp;&nbsp;<a
                            href="InfoServlet?fruitId=${list.fruitId }&i=0">详情</a>&nbsp;&nbsp;<a
                            onclick="Dodelete(${list.fruitId});" href="#">删除</a></td>
                </tr>
            </c:forEach>
        </table>

    </form>
</div>
<script type="text/javascript" src="js/jquery-1.12.4.js"></script>

<script type="text/javascript">
    function Dodelete(fruitId) {
        var flag = confirm("你确定要删除吗？");
        if (flag) {
            $.ajax({
                "url": "DeleteServlet",	//要提交的url路径
                "type": "GET",	//发送的请求方式
                "data": "fruitId=" + fruitId,	//要发送到服务器的数据
                "dataType": "text",		//指定返回的数据格式
                "success": function (data) {	//请求成功后执行该代码
                    if (data > 0) {
                        alert("删除成功！");
                        $("#" + fruitId).remove();
                    } else {
                        alert("删除失败！");
                    }
                },
                "error": function () {		//请求失败后执行该代码
                    alert("删除失败！");
                }
            });
        }
    }
</script>
</body>
</html>
